<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Committing code &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../index.html" />
    <link rel="up" title="Contributing to Django" href="index.html" />
    <link rel="next" title="Mailing lists" href="../mailing-lists.html" />
    <link rel="prev" title="Localizing Django" href="localizing.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="localizing.html" title="Localizing Django">previous</a>
     |
    <a href="../index.html" title="Django internals" accesskey="U">up</a>
   |
    <a href="../mailing-lists.html" title="Mailing lists">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="internals-contributing-committing-code">
            
  <div class="section" id="s-committing-code">
<span id="committing-code"></span><h1>Committing code<a class="headerlink" href="#committing-code" title="Permalink to this headline">¶</a></h1>
<p>This section is addressed to the <a class="reference internal" href="../committers.html"><em>Django committers</em></a> and to anyone
interested in knowing how code gets committed into Django core. If you&#8217;re a
community member who wants to contribute code to Django, have a look at
<a class="reference internal" href="writing-code/working-with-git.html"><em>Working with Git and GitHub</em></a> instead.</p>
<div class="section" id="s-commit-access">
<span id="commit-access"></span><h2>Commit access<a class="headerlink" href="#commit-access" title="Permalink to this headline">¶</a></h2>
<p>Django has two types of committers:</p>
<dl class="docutils">
<dt>Core committers</dt>
<dd>These are people who have a long history of contributions to Django&#8217;s
codebase, a solid track record of being polite and helpful on the
mailing lists, and a proven desire to dedicate serious time to Django&#8217;s
development. The bar is high for full commit access.</dd>
<dt>Partial committers</dt>
<dd><p class="first">These are people who are &#8220;domain experts.&#8221; They have direct check-in
access to the subsystems that fall under their jurisdiction, and they&#8217;re
given a formal vote in questions that involve their subsystems. This type
of access is likely to be given to someone who contributes a large
sub-framework to Django and wants to continue to maintain it.</p>
<p class="last">Partial commit access is granted by the same process as full
committers. However, the bar is set lower; proven expertise in the area
in question is likely to be sufficient.</p>
</dd>
</dl>
<p>Decisions on new committers will follow the process explained in
<a class="reference internal" href="bugs-and-features.html#how-we-make-decisions"><em>How we make decisions</em></a>. To request commit access, please contact an
existing committer privately. Public requests for commit access are potential
flame-war starters, and will simply be ignored.</p>
</div>
<div class="section" id="s-handling-pull-requests">
<span id="s-id1"></span><span id="handling-pull-requests"></span><span id="id1"></span><h2>Handling pull requests<a class="headerlink" href="#handling-pull-requests" title="Permalink to this headline">¶</a></h2>
<p>Since Django is now hosted at GitHub, many patches are provided in the form of
pull requests.</p>
<p>When committing a pull request, make sure each individual commit matches the
commit guidelines described below. Contributors are expected to provide the
best pull requests possible. In practice however, committers - who will likely
be more familiar with the commit guidelines - may decide to bring a commit up
to standard themselves.</p>
<p>Here is one way to commit a pull request:</p>
<div class="highlight-python"><div class="highlight"><pre># Create a new branch tracking upstream/master -- upstream is assumed
# to be django/django.
git checkout -b pull_xxxxx upstream/master

# Download the patches from github and apply them.
curl https://github.com/django/django/pull/xxxxx.patch | git am
</pre></div>
</div>
<p>At this point, you can work on the code. Use <tt class="docutils literal"><span class="pre">git</span> <span class="pre">rebase</span> <span class="pre">-i</span></tt> and <tt class="docutils literal"><span class="pre">git</span>
<span class="pre">commit</span> <span class="pre">--amend</span></tt> to make sure the commits have the expected level of quality.
Once you&#8217;re ready:</p>
<div class="highlight-python"><div class="highlight"><pre># Make sure master is ready to receive changes.
git checkout master
git pull upstream master
# Merge the work as &quot;fast-forward&quot; to master, to avoid a merge commit.
git merge --ff-only pull_xxxxx
# Check that only the changes you expect will be pushed to upstream.
git push --dry-run upstream master
# Push!
git push upstream master

# Get rid of the pull_xxxxx branch.
git branch -d pull_xxxxx
</pre></div>
</div>
<p>An alternative is to add the contributor&#8217;s repository as a new remote,
checkout the branch and work from there:</p>
<div class="highlight-python"><div class="highlight"><pre>git remote add &lt;contributor&gt; https://github.com/&lt;contributor&gt;/django.git
git checkout pull_xxxxx &lt;contributor&gt; &lt;contributor&#39;s pull request branch&gt;
</pre></div>
</div>
<p>Yet another alternative is to fetch the branch without adding the
contributor&#8217;s repository as a remote:</p>
<div class="highlight-python"><div class="highlight"><pre>git fetch https://github.com/&lt;contributor&gt;/django.git &lt;contributor&#39;s pull request branch&gt;
git checkout -b pull_xxxxx FETCH_HEAD
</pre></div>
</div>
<p>At this point, you can work on the code and continue as above.</p>
<p>GitHub provides a one-click merge functionality for pull requests. This should
only be used if the pull request is 100% ready, and you have checked it for
errors (or trust the request maker enough to skip checks). Currently, it isn&#8217;t
possible to check that the tests pass and that the docs build without
downloading the changes to your development environment.</p>
<p>When rewriting the commit history of a pull request, the goal is to make
Django&#8217;s commit history as usable as possible:</p>
<ul class="simple">
<li>If a patch contains back-and-forth commits, then rewrite those into one.
Typically, a commit can add some code, and a second commit can fix
stylistic issues introduced in the first commit.</li>
<li>Separate changes to different commits by logical grouping: if you do a
stylistic cleanup at the same time as you do other changes to a file,
separating the changes into two different commits will make reviewing
history easier.</li>
<li>Beware of merges of upstream branches in the pull requests.</li>
<li>Tests should pass and docs should build after each commit. Neither the
tests nor the docs should emit warnings.</li>
<li>Trivial and small patches usually are best done in one commit. Medium to
large work should be split into multiple commits if possible.</li>
</ul>
<p>Practicality beats purity, so it is up to each committer to decide how much
history mangling to do for a pull request. The main points are engaging the
community, getting work done, and having a usable commit history.</p>
</div>
<div class="section" id="s-committing-guidelines">
<span id="s-id2"></span><span id="committing-guidelines"></span><span id="id2"></span><h2>Committing guidelines<a class="headerlink" href="#committing-guidelines" title="Permalink to this headline">¶</a></h2>
<p>In addition, please follow the following guidelines when committing code to
Django&#8217;s Git repository:</p>
<ul>
<li><p class="first">Never change the published history of django/django branches! <strong>Never force-
push your changes to django/django.</strong> If you absolutely must (for security
reasons for example) first discuss the situation with the core team.</p>
</li>
<li><p class="first">For any medium-to-big changes, where &#8220;medium-to-big&#8221; is according to
your judgment, please bring things up on the <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><em>django-developers</em></a>
mailing list before making the change.</p>
<p>If you bring something up on <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><em>django-developers</em></a> and nobody responds,
please don&#8217;t take that to mean your idea is great and should be
implemented immediately because nobody contested it. Django&#8217;s lead
developers don&#8217;t have a lot of time to read mailing-list discussions
immediately, so you may have to wait a couple of days before getting a
response.</p>
</li>
<li><p class="first">Write detailed commit messages in the past tense, not present tense.</p>
<ul class="simple">
<li>Good: &#8220;Fixed Unicode bug in RSS API.&#8221;</li>
<li>Bad: &#8220;Fixes Unicode bug in RSS API.&#8221;</li>
<li>Bad: &#8220;Fixing Unicode bug in RSS API.&#8221;</li>
</ul>
<p>The commit message should be in lines of 72 chars maximum. There should be
a subject line, separated by a blank line and then paragraphs of 72 char
lines. The limits are soft. For the subject line, shorter is better. In the
body of the commit message more detail is better than less:</p>
<div class="highlight-python"><div class="highlight"><pre>Fixed #18307 -- Added git workflow guidelines

Refactored the Django&#39;s documentation to remove mentions of SVN
specific tasks. Added guidelines of how to use Git, GitHub, and
how to use pull request together with Trac instead.
</pre></div>
</div>
<p>If the patch wasn&#8217;t a pull request, you should credit the contributors in
the commit message: &#8220;Thanks A for report, B for the patch and C for the
review.&#8221;</p>
</li>
<li><p class="first">For commits to a branch, prefix the commit message with the branch name.
For example: &#8220;[1.4.x] Fixed #xxxxx &#8211; Added support for mind reading.&#8221;</p>
</li>
<li><p class="first">Limit commits to the most granular change that makes sense. This means,
use frequent small commits rather than infrequent large commits. For
example, if implementing feature X requires a small change to library Y,
first commit the change to library Y, then commit feature X in a
separate commit. This goes a <em>long way</em> in helping all core Django
developers follow your changes.</p>
</li>
<li><p class="first">Separate bug fixes from feature changes. Bugfixes may need to be backported
to the stable branch, according to the <a class="reference internal" href="../release-process.html#backwards-compatibility-policy"><em>backwards-compatibility policy</em></a>.</p>
</li>
<li><p class="first">If your commit closes a ticket in the Django <a class="reference external" href="https://code.djangoproject.com/newticket">ticket tracker</a>, begin
your commit message with the text &#8220;Fixed #xxxxx&#8221;, where &#8220;xxxxx&#8221; is the
number of the ticket your commit fixes. Example: &#8220;Fixed #123 &#8211; Added
whizbang feature.&#8221;. We&#8217;ve rigged Trac so that any commit message in that
format will automatically close the referenced ticket and post a comment
to it with the full commit message.</p>
<p>If your commit closes a ticket and is in a branch, use the branch name
first, then the &#8220;Fixed #xxxxx.&#8221; For example:
&#8220;[1.4.x] Fixed #123 &#8211; Added whizbang feature.&#8221;</p>
<p>For the curious, we&#8217;re using a <a class="reference external" href="https://github.com/aaugustin/trac-github">Trac plugin</a> for this.</p>
</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Note that the Trac integration doesn&#8217;t know anything about pull requests.
So if you try to close a pull request with the phrase &#8220;closes #400&#8221; in your
commit message, GitHub will close the pull request, but the Trac plugin
will also close the same numbered ticket in Trac.</p>
</div>
<ul>
<li><p class="first">If your commit references a ticket in the Django <a class="reference external" href="https://code.djangoproject.com/newticket">ticket tracker</a> but
does <em>not</em> close the ticket, include the phrase &#8220;Refs #xxxxx&#8221;, where &#8220;xxxxx&#8221;
is the number of the ticket your commit references. This will automatically
post a comment to the appropriate ticket.</p>
</li>
<li><p class="first">Write commit messages for backports using this pattern:</p>
<div class="highlight-python"><div class="highlight"><pre>[&lt;Django version&gt;] Fixed &lt;ticket&gt; -- &lt;description&gt;

Backport of &lt;revision&gt; from &lt;branch&gt;.
</pre></div>
</div>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre>[1.3.x] Fixed #17028 - Changed diveintopython.org -&gt; diveintopython.net.

Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
</pre></div>
</div>
</li>
</ul>
</div>
<div class="section" id="s-reverting-commits">
<span id="reverting-commits"></span><h2>Reverting commits<a class="headerlink" href="#reverting-commits" title="Permalink to this headline">¶</a></h2>
<p>Nobody&#8217;s perfect; mistakes will be committed.</p>
<p>But try very hard to ensure that mistakes don&#8217;t happen. Just because we have a
reversion policy doesn&#8217;t relax your responsibility to aim for the highest
quality possible. Really: double-check your work, or have it checked by
another committer, <strong>before</strong> you commit it in the first place!</p>
<p>When a mistaken commit is discovered, please follow these guidelines:</p>
<ul class="simple">
<li>If possible, have the original author revert their own commit.</li>
<li>Don&#8217;t revert another author&#8217;s changes without permission from the
original author.</li>
<li>Use git revert &#8211; this will make a reverse commit, but the original
commit will still be part of the commit history.</li>
<li>If the original author can&#8217;t be reached (within a reasonable amount
of time &#8211; a day or so) and the problem is severe &#8211; crashing bug,
major test failures, etc &#8211; then ask for objections on the
<a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><em>django-developers</em></a> mailing list then revert if there are none.</li>
<li>If the problem is small (a feature commit after feature freeze,
say), wait it out.</li>
<li>If there&#8217;s a disagreement between the committer and the
reverter-to-be then try to work it out on the <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><em>django-developers</em></a>
mailing list. If an agreement can&#8217;t be reached then it should
be put to a vote.</li>
<li>If the commit introduced a confirmed, disclosed security
vulnerability then the commit may be reverted immediately without
permission from anyone.</li>
<li>The release branch maintainer may back out commits to the release
branch without permission if the commit breaks the release branch.</li>
<li>If you mistakenly push a topic branch to django/django, just delete it.
For instance, if you did: <tt class="docutils literal"><span class="pre">git</span> <span class="pre">push</span> <span class="pre">upstream</span> <span class="pre">feature_antigravity</span></tt>,
just do a reverse push: <tt class="docutils literal"><span class="pre">git</span> <span class="pre">push</span> <span class="pre">upstream</span> <span class="pre">:feature_antigravity</span></tt>.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Committing code</a><ul>
<li><a class="reference internal" href="#commit-access">Commit access</a></li>
<li><a class="reference internal" href="#handling-pull-requests">Handling pull requests</a></li>
<li><a class="reference internal" href="#committing-guidelines">Committing guidelines</a></li>
<li><a class="reference internal" href="#reverting-commits">Reverting commits</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="localizing.html">Localizing Django</a></li>
    
    
      <li>Next: <a href="../mailing-lists.html">Mailing lists</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../index.html">Django internals</a>
        
          <ul><li><a href="index.html">Contributing to Django</a>
        
        <ul><li>Committing code</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/internals/contributing/committing-code.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="localizing.html" title="Localizing Django">previous</a>
     |
    <a href="../index.html" title="Django internals" accesskey="U">up</a>
   |
    <a href="../mailing-lists.html" title="Mailing lists">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>